package com.hzt.agprosaleplatform.service.impl;

import com.hzt.agprosaleplatform.entity.FinanceApplicationVO;
import com.hzt.agprosaleplatform.mapper.AdminFinanceMapper;
import com.hzt.agprosaleplatform.service.AdminFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AdminFinanceServiceImpl implements AdminFinanceService {

    @Autowired
    private AdminFinanceMapper adminFinanceMapper;

    @Override
    public List<FinanceApplicationVO> getAllApplications() {
        return adminFinanceMapper.selectAllApplications();
    }

    @Override
    public boolean approveApplication(Integer financeId, String opinion) {
        int result = adminFinanceMapper.updateStatusWithTime(financeId, 1, opinion, new Date());
        return result > 0;
    }

    @Override
    public boolean rejectApplication(Integer financeId, String opinion) {
        int result = adminFinanceMapper.updateStatusWithTime(financeId, 2, opinion, new Date());
        return result > 0;
    }

    @Override
    public boolean disburseApplication(Integer financeId, String opinion) {
        int result = adminFinanceMapper.updateStatusWithTime(financeId, 3, opinion, new Date());
        return result > 0;
    }
    
    @Override
    public boolean repayApplication(Integer financeId, String opinion) {
        int result = adminFinanceMapper.updateStatusWithTime(financeId, 4, opinion, new Date());
        return result > 0;
    }
}